<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./axios.js"></script>
</head>

<body>
  <h1>我是登录页面</h1>
  用户名： <input type="text" class="username"><br>
  密码 : <input type="password" class="pwd"><br>
  <button>点击我登录</button>
  <script>
    let btn = document.querySelector("button");
    let usernameEle = document.querySelector(".username");
    let pwdEle = document.querySelector(".pwd");
    btn.onclick = async function () {
      let username = usernameEle.value;
      let pwd = pwdEle.value;
      let { data: { token, status } } = await axios.post("/checkUser", { username, pwd });
      console.log("token:" + token, "status:" + status);
      // console.log(data);
      // alert(data.info);
      if (status === 1) {
        // 获取token ，保存下来 ；
        localStorage.setItem("token", token);
        window.location.href = "/index";
      }
    }


  </script>
</body>

</html>